//
//  main.m
//  ChildCommandLineTool
//
//  Created by LiuLichen on 2023/6/19.
//

#import <Foundation/Foundation.h>

@interface MyTaskManager : NSObject

+ (instancetype)sharedManager;
- (void)startTask;

@end

@implementation MyTaskManager

+ (instancetype)sharedManager {
    static MyTaskManager *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[self alloc] init];
    });
    return sharedInstance;
}

- (void)startTask {
    // 在这里添加你想要执行的任务代码
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}

- (void)timerFired:(NSTimer *)timer {
    // 在这里添加你想要执行的定时任务
    exit(0);
}

@end

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // 创建单例对象并执行任务
        MyTaskManager *taskManager = [MyTaskManager sharedManager];
        [taskManager startTask];

        // 创建一个永久运行的任务
        [[NSRunLoop currentRunLoop] run];
    }
    return 0;
}
